package com.example.base.http

import android.content.Context
import androidx.room.Room
import com.example.base.room.ParkDataBase
import com.example.base.room.UserDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object Provider {
    @Provides
    @Singleton
    fun apiServer(): ApiServer = RetFitUtils.retrofit().create(ApiServer::class.java)

    @Provides
    @Singleton
    fun initDB(@ApplicationContext context: Context):ParkDataBase{
        return Room.databaseBuilder(context, ParkDataBase::class.java, "park2302.db")
            .allowMainThreadQueries().build()
    }

    @Singleton
    @Provides
    fun getUserDao(dataBase: ParkDataBase): UserDao {
        return dataBase.userDao()
    }
}